package com.globalwave.pos.inventory;

import java.util.List;

import org.junit.Ignore;

import com.globalwave.pos.inventory.entity.InventoryBalance;
import com.globalwave.pos.inventory.entity.InventoryPeriod;
import com.globalwave.pos.inventory.entity.InventoryPeriodBalance;
import com.globalwave.pos.inventory.entity.InventoryTransaction;
import com.globalwave.test.BaseTestCase;

@Ignore
public class InventoryBaseTestCase extends BaseTestCase {

	
    protected String warehouseCode = "UTC1" ;
    protected String warehouseCode2 = "UTC2" ;
    protected Long stockItemNum1 = 12345L ;
    protected Long stockItemNum2 = 23456L ;


    // -------------------------- get/query po --------------------------
	public InventoryPeriod getPeriod(Long periodId) throws Exception {
    	return (InventoryPeriod)get(InventoryPeriod.class, new String[]{"periodId=" + periodId}) ;
    }

	protected InventoryBalance getBalance(String warehouseCode, Long stockItem) throws Exception {
		 return (InventoryBalance)get(
					InventoryBalance.class, 
					new String[]{"warehouse_Code='" + warehouseCode + "'", "stock_Item_Number=" + stockItem}) ; 
	}
	
	protected InventoryPeriodBalance getPeriodBalance(String warehouseCode, Long stockItem, Integer periodId) throws Exception {
		 return (InventoryPeriodBalance)get(
					InventoryPeriodBalance.class, 
					new String[]{"warehouse_Code='" + warehouseCode + "'", "stock_Item_Number=" + stockItem, "period_Id=" + periodId}) ; 
	}
	
	protected InventoryTransaction getTempTransaction(String warehouseCode, Long stockItem) throws Exception {
		 return (InventoryTransaction)get(
				 InventoryTransaction.class, 
					new String[]{"warehouse_Code='" + warehouseCode + "'", "stock_Item_Number=" + stockItem}) ; 
	}
	
	protected List<Object> queryTempTransaction(String warehouseCode, Long stockItem) throws Exception {
		 return (List<Object>)query(
				 InventoryTransaction.class, 
					new String[]{"warehouse_Code='" + warehouseCode + "'", "stock_Item_Number=" + stockItem}) ; 
	}
	
	protected List<Object> queryBalance(String warehouseCode, Long stockItem) throws Exception {
		 return (List<Object>)query(
				 InventoryBalance.class, 
					new String[]{"warehouse_Code='" + warehouseCode + "'", "stock_Item_Number=" + stockItem}) ; 
	}

	// ----------------- get bo ------------------------------------------------
/*
	public InventoryBOImpl getInventoryBO() {
		if (inventoryBO == null) {
			this.inventoryBO = new InventoryBOImpl(){
				protected ItemBO getItemBean(PosContext posCtx){	
					if (itemBO == null) {
						itemBO = new com.amway.pos5g.bizlogic.item.cn.ItemBOImpl() ;
						itemBO.setInventoryBO(this) ;
						this.setItemBO(itemBO) ;
					} 
					
					return itemBO ;
				}
			};
			//this.inventoryBO.setAccessor(this.accessor) ;
			this.inventoryBO.setWarehouseCode(this.warehouseCode) ;
		}
		return inventoryBO;
    }


    public ItemBOImpl getItemBO() {
    	if (itemBO == null) {
	    	itemBO =  new ItemBOImpl() {
	    		protected InventoryBO getInventoryBean(PosContext posCtx){	
	    			if (inventoryBO == null) {
	    				inventoryBO = new InventoryBOImpl() ;
	    				this.setInventoryBO(inventoryBO) ;
	    				inventoryBO.setItemBO(this) ;
	    			} 
	    			return inventoryBO ;
	    		}
	    	};
	    	//itemBO.setAccessor(accessor) ;
    	}
    	return itemBO ;
    }
    */
	// ----------------- assert balance ------------------------------------------------
	
	public void assertBalance(String msg, InventoryBalance objExpected, InventoryBalance objActual) throws Exception {
		String showMsg = msg + "(" + objActual.getWarehouse_code() + "," + objActual.getStock_item_number() + ")" ;
		assertObject(showMsg, objExpected, objActual, new String[]{"on_hand_quantity", "mortgaged_quantity"}) ;
		
	}
	
	public void assertTempTransaction(String msg, InventoryTransaction objExpected, InventoryTransaction objActual) throws Exception {
		String showMsg = msg + "(" + objActual.getWarehouse_code() + "," + objActual.getStock_item_number() + ")" ;
		assertObject(showMsg, objExpected, objActual, new String[]{"transactionQuantity", "transactionCode"}) ;
		
	}

	
	public void assertPeriod(String msg, InventoryPeriod objExpected, InventoryPeriod objActual) throws Exception {
		String showMsg = msg + "(" + objActual.getId() + ")" ;
		assertObject(showMsg, objExpected, objActual, new String[]{"endDate", "startDate", "periodStatus"}) ;
		
	}


	
	public void assertPeriodBalance(String msg, InventoryPeriodBalance objExpected, InventoryPeriodBalance objActual) throws Exception {
		String showMsg = msg + "(" + objActual.getPeriodId() + ", " + objActual.getWarehouseCode() + ", " + objActual.getStockItemNumber() + ")" ;
		assertObject(showMsg, objExpected, objActual, new String[]{"onHandBalance"}) ;
		
	}
}
